package com.sbl.bajw.pc.action;

import java.util.HashMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sbl.bajw.pc.model.policeInfoModel;
import com.sbl.bajw.pc.service.policeInfoModelService;

@Controller
@RequestMapping("/policeInfo")
public class policeInfoModelAction {
	@Resource
	private policeInfoModelService service;
	
	@RequestMapping(value = "/getGridByOrg")
	public @ResponseBody String getGridByOrg(HttpServletRequest request, HttpServletResponse response) throws Exception{
		HashMap<String, Object> parm = new HashMap<String, Object>();
		String orgcode = request.getParameter("orgcode");
		String zd = request.getParameter("zd");
		String app = request.getParameter("app");
		parm.put("orgcode", orgcode + "%");
		if(zd != null && "".equals(zd)){
			parm.put("zd", zd);
		}
		if(app != null && "".equals(app)){
			parm.put("app", app);
		}
		String json = service.getGridByOrg(parm);
		return json;
	}
	
	@RequestMapping(value = "/getModelList")
	public @ResponseBody String getModelList(HttpServletRequest request, HttpServletResponse response) throws Exception{
		HashMap<String, Object> parm = new HashMap<String, Object>();
		String json = service.getGridByOrg(parm);
		return json;
	}
	
	@RequestMapping(value = "/getModelById")
	public ModelAndView getModelById(HttpServletRequest request, HttpServletResponse response){
		String id = request.getParameter("id");
		policeInfoModel model = service.getGridById(id);
		request.setAttribute("model", model);
		ModelAndView mav = new ModelAndView("/view/grid/policePeople");
		return mav;
	}
	
	@RequestMapping(value = "/getModelByConditions")
	public @ResponseBody String getModelByConditions(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String xm = request.getParameter("xm");
		String jh = request.getParameter("jh");
		String sex = request.getParameter("sex");
		String card = request.getParameter("card");
		String phone = request.getParameter("phone");
		String fullid = request.getParameter("fullid");
		String leader = request.getParameter("leader");
		String jw = request.getParameter("jw");
		String zd = request.getParameter("zd");
		String app = request.getParameter("app");
		HashMap<String, Object> parm = new HashMap<String, Object>();
		if(xm != null && "".equals(xm)){
			parm.put("xm", "%" + xm + "%");
		}
		if(jh != null && "".equals(jh)){
			parm.put("jh", "%" + jh + "%");
		}
		parm.put("sex", sex);
		if(card != null && "".equals(card)){
			parm.put("card", "%" + card + "%");
		}
		if(phone != null && "".equals(phone)){
			parm.put("phone", "%" + phone + "%");
		}
		parm.put("fullid", fullid + "%");
		if(leader != null && "".equals(leader)){
			parm.put("leader", "%" + leader + "%");
		}
		if(jw != null && "".equals(jw)){
			parm.put("jw", "%" + jw + "%");
		}
		parm.put("zd", zd);
		parm.put("app", app);
		String json = service.getModelByConditions(parm);
		return json;
	}
}
